package com.yuch.service.impl;

import com.yuch.service.SendSMS;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Service;

import javax.mail.internet.MimeMessage;

//@Service
public class SendMailServiceImpl2 implements SendSMS {
    @Autowired
    private JavaMailSender javaMailSender;

    //发送人
    private String from = "3060186113@qq.com";
    //接收人
    private String to = "ych4912@163.com";
    //标题
    private String subject = "测试邮件";
    //正文
    private String context = "<img src='https://cn.bing.com/images/search?view=detailV2&ccid=b39hvvD0&id=59AFEC50707AD1876BBA7BF097235ABE6D08D8CE&thid=OIP.b39hvvD0k83rsxpCvwWf7QHaQC&mediaurl=https%3a%2f%2fwww.qqkw.com%2fd%2ffile%2fp%2f2018%2f05-17%2f0515954b9ce3b4eee4774a73406ed5b6.jpg&exph=2436&expw=1125&q=%e7%be%8e%e5%a5%b3&simid=608029664393583591&FORM=IRPRST&ck=267CEEC34F81BA311B234C292FF199DC&selectedIndex=0'/><a href='https://www.itcast.cn'>点开有惊喜</a>";

    @Override
    public void sendsms() {
        try {
            MimeMessage message = javaMailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message);
            helper.setFrom(from+"(小甜甜)");
            helper.setTo(to);
            helper.setSubject(subject);
            helper.setText(context,true);		//此处设置正文支持html解析

            javaMailSender.send(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}